package com.heima.wemedia.scan.listener;

import com.heima.common.constants.KafkaMessageConstants;
import com.heima.wemedia.scan.service.WmNewsAutoScanService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

/**
 * kafka监听器
 */
@Component
@Slf4j
public class NewsAutoScanListener {

    @Autowired
    private WmNewsAutoScanService wmNewsAutoScanService;

    @KafkaListener(topics = KafkaMessageConstants.WM_NEWS_AUTO_SCAN_TOPIC,groupId = "WM_NEWS_AUTO_SCAN")
    public void wmNewsAutoScan(ConsumerRecord<String, String> record){
        String value = record.value();
        log.info("接收到消息，内容为：{}",value);
        if (StringUtils.isNotBlank(value)) {
            //调用文章审核业务
            log.info("文章审核开始----------");
            wmNewsAutoScanService.autoScanNews(Long.valueOf(value));
            log.info("文章审核结束:{}",record);
        }
    }
}
